package com.w.usercenter.controller;

import com.w.usercenter.common.BaseResponse;
import com.w.usercenter.common.ResultUtils;
import com.w.usercenter.mode.domain.User;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.context.annotation.Profile;
import org.springframework.web.bind.annotation.*;

/**
 * knif4j 官网: https://doc.xiaominfo.com/docs/quick-start
 * 访问Knife4j的文档地址：http://ip:port/doc.html 即可查看文档
 * 配合 open api 3(swagger.v3)注解使用示例
 *
 * @author wzp
 * @since 2024/8/21
 */
//配合@Profile({"dev"})注解,可以控制某一些类不对外暴露,或者在配置类中进行调整paths-to-match属性
@Profile({"prod"})
@RestController
@RequestMapping("body")
@Tag(name = "BodyController 控制器", description = "BodyController 描述信息")
public class BodyController {

    @Operation(summary = "body的摘要信息", description = "body 的详细描述信息")
    @PostMapping("/body")
    public BaseResponse<?> body(@RequestBody User user) {
        return ResultUtils.succeed(user);
    }

    @Operation(summary = "Path+Header+Param+普通body请求 的示例")
    @Parameters({
            @Parameter(name = "id", description = "文件id", in = ParameterIn.PATH),
            @Parameter(name = "token", description = "请求token", required = true, in = ParameterIn.HEADER),
            @Parameter(name = "name", description = "文件名称", required = true, in = ParameterIn.QUERY)
    })
    @PostMapping("/bodyParamHeaderPath/{id}")
    public BaseResponse<?> bodyParamHeaderPath(@PathVariable("id") String id, @RequestHeader("token") String token, @RequestParam("name") String name, @RequestBody User user) {
        String result = "RequestBody:" + user.getUsername() + ",RequestParam:" + name + ",RequestHeader:" + token + ",PathVariable:" + id;
        return ResultUtils.succeed(result);
    }
}
